local skill = fk.CreateSkill{
  name = "tea__zhiyue"
}
---@type TrigSkelSpec<TrigFunc>
local zhiyue = {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and not player.dead
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(3)
    room:moveCards({
      ids = cards,
      toArea = Card.Processing,
      moveReason = fk.ReasonPut,
      skillName = self.name,
      proposer = player
    })
    local choosecards = room:askToCards(player, {
      min_num = 1,
      max_num = 3,
      include_equip = false,
      skill_name = self.name,
      pattern = tostring(Exppattern{ id = cards }),
      expand_pile = cards,
      prompt = "#zhiyue_choosecards",
    }) or {}
    if #choosecards > 0 then
      local targets = room.alive_players
      local toid = room:askToChoosePlayers(player, {
        targets = targets,
        min_num = 1,
        max_num = 1,
        prompt = "#zhiyue_chooseto",
        skill_name = self.name,
        cancelable = false,
      })
      if #toid == 1 then
        local to = toid[1]
        room:obtainCard(to, choosecards, true, fk.ReasonGive, player.id)
        if not to.dead then
          local suits = room:askToChoices(to, {
            choices = {"log_heart", "log_diamond", "log_spade", "log_club"},
            min_num = #choosecards,
            max_num = #choosecards,
            skill_name = self.name,
            prompt = "#zhiyue-choice:::"..#choosecards,
            cancelable = false,
          })
          local discards = {}
          to:showCards(to.player_cards[Player.Hand])
          local inhand = to:getCardIds(Player.Hand)
          for _, id in ipairs(inhand) do
            if id > 0 then
              if table.contains(suits, Fk:getCardById(id):getSuitString(true)) then
                table.insert(discards, id)
              end
            end
          end
          if #discards > 0 then
            room:delay(500)
            room:throwCard(discards, self.name, to, to)
          end
        end
      end
    end
  end,
}
skill:addEffect(fk.Damaged, zhiyue)

return skill